/**
 * via https://app.storyblok.com
 */

import Koa from 'koa';
import fetch from '../fetch';
import Router from 'koa-router';
import { errLog } from '../log';
import { packageRouter, packageResponse } from '../util';

function useRouter(router: Router, app: Koa): void {
    // ...
    const route = packageRouter(router, app);

    route('get', '/getNotaList', async ({ response }) => {
        try {
            const result = await fetch.post('https://api.storyblok.com/v2/cdn/stories/nota?cv=1678118483&token=QvVcQ42Iw2lKMzJn2spv4Qtt&version=published');
            packageResponse(response, result);

            // ...
        } catch (error) {
            errLog(error);
            packageResponse(response, null, 0, 500, JSON.stringify(error));
        }
    });
}

export default useRouter;
